"""
Django settings for DAMN project.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


from ConfigParser import RawConfigParser
config = RawConfigParser()
localDir = os.path.abspath(os.path.dirname(__file__))
#In order of priority
fileNames = config.read([os.path.join(BASE_DIR, 'settings.cfg'),            #Default settings, lowest priority
                         '/etc/damn/settings.cfg',                          #System settings
                         os.path.expanduser('~/.damn/settings.cfg'),        #User settings
                         os.path.join(BASE_DIR, 'settings-override.cfg')])  #Global override, highest priority       
print "Configuration read from the following file(s)", fileNames




SITE_ID = 1

# SECURITY WARNING: keep the secret key used in production secret!
# Hardcoded values can leak through source control. Consider loading
# the secret key from an environment variable or a file instead.
SECRET_KEY = '314$p#ak*z+%@9%+me_3_ygai0qengvc(z62#xifcw@b)1d95w'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []


# Authentication backends
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'sso.authbackend.NameBackend',
)


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    'django.contrib.sites',
    'django.contrib.comments',
    'piston',
    'sso',
    'webgui',
    'files',
    'assets',
    'anvil',  
    'jobs',
    'ratings', 
    'feeds',
    'profiles',
    'repositories',
    'tags',
    'configuration',
    'favorites',
    'registrations',
    'comments',
    'blogs',
    'damnfs',
)
COMMENTS_APP = 'comments'


MIDDLEWARE_CLASSES = (
    'django.middleware.gzip.GZipMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'sso.middleware.SingleSignOnMiddleware', #Needs to be AFTER session middleware
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'damnweb.urls'

WSGI_APPLICATION = 'damnweb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASE_ENGINE = config.get('database', 'DATABASE_ENGINE')
DATABASE_NAME = config.get('database', 'DATABASE_NAME')
DATABASE_USER = config.get('database', 'DATABASE_USER')
DATABASE_PASSWORD = config.get('database', 'DATABASE_PASSWORD')
DATABASE_HOST = config.get('database', 'DATABASE_HOST')
DATABASE_PORT = config.get('database', 'DATABASE_PORT')
print DATABASE_ENGINE, DATABASE_NAME, DATABASE_USER

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.'+DATABASE_ENGINE, # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': DATABASE_NAME, # Or path to database file if using sqlite3.
        'USER': DATABASE_USER,                      # Not used with sqlite3.
        'PASSWORD': DATABASE_PASSWORD,                  # Not used with sqlite3.
        'HOST': DATABASE_HOST,                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': DATABASE_PORT,
    }
}


# E-mail and Registration
#python -m smtpd -n -c DebuggingServer localhost:1025
EMAIL_BACKEND = config.get('email', 'EMAIL_BACKEND')
EMAIL_HOST = config.get('email', 'EMAIL_HOST')
EMAIL_PORT = config.getint('email', 'EMAIL_PORT')
EMAIL_HOST_USER = config.get('email', 'EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config.get('email', 'EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = config.getboolean('email', 'EMAIL_USE_TLS')

ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = True


# Caches
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        #'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        'LOCATION': 'asset-caches'
    }
}

# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = config.get('static', 'STATIC_ROOT')




"""
Needed for uploaded files 'store', should be deprecated in favor of custom
https://docs.djangoproject.com/en/dev/howto/custom-file-storage/
with a Configuration object in the DB like 'ASSETS_EXPORT_DIR'
"""
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/tmp/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/uploaded/'
